package com.xuecheng.media.conver;

import com.xuecheng.content.model.message.VideoProcessMessage;
import com.xuecheng.content.model.po.MediaProcessHistory;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.Optional;

public class VideoProcessMessageConver {

    public MediaProcessHistory videoProcessMessageConverToMediaProcessHistory(VideoProcessMessage videoProcessMessage){
        MediaProcessHistory mediaProcessHistory = new MediaProcessHistory();
        BeanUtils.copyProperties(videoProcessMessage,mediaProcessHistory);
        mediaProcessHistory.setUrl(videoProcessMessage.getOriginalUrl());
        mediaProcessHistory.setFilePath(videoProcessMessage.getOriginalUrl());
        mediaProcessHistory.setCreateDate(LocalDateTime.now());
        Optional.ofNullable(videoProcessMessage.getCreateTime()).ifPresent(item -> {videoProcessMessage.setCreateTime(videoProcessMessage.getCreateTime());});
        mediaProcessHistory.setFinishDate(LocalDateTime.now());
        mediaProcessHistory.setStatus("3");
        return mediaProcessHistory;
    }
}
